<?php
/**
 * Local variables
 * @var \Phalcon\Mvc\View\Engine $this
 * @var null|string $controllersDir
 * @var closure $fileOwner Get file owner/group closure
 */
?>

<h1 class="page-header">Edit Controllers</h1>

<div class="row">
    <div class="col-md-12">
        <?php echo $this->getContent() ?>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <table class="table table-bordered table-striped">
            <thead>
                <tr>
                    <th>Name</th>
                    <th width="10%">Size</th>
                    <th width="15%">Owner</th>
                    <th width="10%">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if (!$controllersDir): ?>
                    <tr class="warning">
                        <td colspan="4">
                            <p class="text-center lead">
                                Sorry, WebTools doesn't know where the controllers directory is.<br>
                                Please add the valid path for <code>controllersDir</code> in the <code>application</code> section.
                            </p>
                        </td>
                    </tr>
                <?php else: ?>
                    <?php $iterator = new DirectoryIterator($controllersDir); foreach($iterator as $file): ?>
                        <?php if (!$file->isDot() && 0 !== strrpos($file->getBasename(), '.')): ?>
                            <tr>
                                <td>
                                    <?php echo $file->getBasename('.php'); ?>
                                </td>
                                <td><?php echo $file->getSize() . ' b' ?></td>
                                <td><?php echo $fileOwner($file); ?></td>
                                <td>
                                    <?php if ($file->isWritable()): ?>
                                        <a href="<?php echo $this->url->get(sprintf('webtools.php?_url=/controllers/edit/%s', $file->getFileName())) ?>" class="btn btn-link">Edit</a>
                                    <?php else: ?>
                                        <a href="<?php echo $this->url->get(sprintf('webtools.php?_url=/controllers/edit/%s', $file->getFileName())) ?>" class="btn btn-link">Readonly</a>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endif; ?>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
